home *** CD-ROM | disk | FTP | other *** search
/ The Sunday Times: The Month 2004 August / The Sunday Times - The Month 2004-08.iso / pc / engine / modules / fader.swf / scripts / frame_1 / DoAction.as
Encoding:
Text File  |  2004-06-24  |  4.1 KB  |  188 lines

  1. function init()
  2. {
  3.    strPath = Tardis.ASSETS_FOLDER + "images/" + Tardis.ActiveSection.id + "/";
  4.    var i = 0;
  5.    while(i < nodeData.childNodes.length)
  6.    {
  7.       var mc = this.createEmptyMovieClip("mImage_" + i,10 + i);
  8.       mc.imagePath = nodeData.childNodes[i].getText();
  9.       mc.origDepth = 10 + i;
  10.       mc.id = i;
  11.       mc.loadImage = function()
  12.       {
  13.          this.createEmptyMovieClip("mImage",2);
  14.          this.mImage.loadMovie(this._parent.strPathPrefix + this._parent.strPath + this.imagePath);
  15.          this.onEnterFrame = function()
  16.          {
  17.             if(this.mImage._height > 0)
  18.             {
  19.                this.isImageLoaded = 1;
  20.                delete this.onEnterFrame;
  21.                this.onImageLoaded();
  22.             }
  23.          };
  24.       };
  25.       mc.fadeIn = function()
  26.       {
  27.          if(!this.isImageLoaded)
  28.          {
  29.             this.loadImage();
  30.          }
  31.          this._alpha = 0;
  32.          this._visible = 1;
  33.          this.swapDepths(100);
  34.          this._parent.fading = this;
  35.          this.onEnterFrame = function()
  36.          {
  37.             this._alpha += 2;
  38.             if(this._alpha >= 100)
  39.             {
  40.                this._alpha = 100;
  41.                this.swapDepths(this.origDepth);
  42.                this.onEnterFrame = null;
  43.                this._parent.setCurrentImage(this.id);
  44.                this._parent.onFadeComplete();
  45.             }
  46.          };
  47.       };
  48.       mc.showNow = function()
  49.       {
  50.          delete this.onEnterFrame;
  51.          if(!this.isImageLoaded)
  52.          {
  53.             this.loadImage();
  54.          }
  55.          this._alpha = 100;
  56.          this._visible = 1;
  57.          this._parent.setCurrentImage(this.id);
  58.       };
  59.       mc.hideNow = function()
  60.       {
  61.          delete this.onEnterFrame;
  62.          this._alpha = 0;
  63.          this._visible = 0;
  64.       };
  65.       arrImages.push(mc);
  66.       i++;
  67.    }
  68.    fading = paused = 0;
  69.    if(arrImages.length > 1 && nodeData.attributes.controls == "true")
  70.    {
  71.       mImage_0.onImageLoaded = function()
  72.       {
  73.          var mc = attachMovie("clp_controls","mc_controls",400);
  74.          mc._x = mImage_0._width - (mc._width - 12) - 10;
  75.          mc._y = mImage_0._height - (mc._height - 11) - 10;
  76.       };
  77.    }
  78.    mImage_0.showNow();
  79.    if(arrImages.length > 1)
  80.    {
  81.       delay();
  82.    }
  83.    onComplete();
  84. }
  85. depth = 0;
  86. var strPathPrefix;
  87. var nmDelay = 4000;
  88. var arrImages = [];
  89. var strPath;
  90. this.onUnload = function()
  91. {
  92.    clearInterval(delayIntervalID);
  93. };
  94. onDelayComplete = function()
  95. {
  96.    clearInterval(delayIntervalID);
  97.    delayIntervalID = null;
  98.    if(paused != 1)
  99.    {
  100.       nextImage.fadeIn();
  101.    }
  102. };
  103. onFadeComplete = function()
  104. {
  105.    prevImage.hideNow();
  106.    if(paused != 1)
  107.    {
  108.       delay();
  109.    }
  110. };
  111. delay = function()
  112. {
  113.    clearInterval(delayIntervalID);
  114.    delayIntervalID = setInterval(this,"onDelayComplete",nmDelay);
  115. };
  116. skipPrev = function()
  117. {
  118.    if(delayIntervalID != null)
  119.    {
  120.       clearInterval(delayIntervalID);
  121.       delayIntervalID = null;
  122.    }
  123.    if(fading)
  124.    {
  125.       currImage.showNow();
  126.       nextImage.hideNow();
  127.       fading = 0;
  128.    }
  129.    else
  130.    {
  131.       currImage.hideNow();
  132.       prevImage.showNow();
  133.    }
  134.    delay();
  135. };
  136. skipNext = function()
  137. {
  138.    if(delayIntervalID != null)
  139.    {
  140.       clearInterval(delayIntervalID);
  141.       delayIntervalID = null;
  142.    }
  143.    if(fading)
  144.    {
  145.       fading = 0;
  146.    }
  147.    currImage.hideNow();
  148.    nextImage.showNow();
  149.    delay();
  150. };
  151. pause = function()
  152. {
  153.    clearInterval(delayIntervalID);
  154.    delayIntervalID = null;
  155.    if(paused == 1)
  156.    {
  157.       paused = 0;
  158.       if(!fading)
  159.       {
  160.          onDelayComplete();
  161.       }
  162.    }
  163.    else
  164.    {
  165.       paused = 1;
  166.    }
  167. };
  168. setCurrentImage = function(id)
  169. {
  170.    this.currImage = this["mImage_" + id];
  171.    if(id == 0)
  172.    {
  173.       this.prevImage = this["mImage_" + (arrImages.length - 1)];
  174.    }
  175.    else
  176.    {
  177.       this.prevImage = this["mImage_" + (id - 1)];
  178.    }
  179.    if(id == arrImages.length - 1)
  180.    {
  181.       this.nextImage = mImage_0;
  182.    }
  183.    else
  184.    {
  185.       this.nextImage = this["mImage_" + (id + 1)];
  186.    }
  187. };
  188.